// const arr = [undefined, null, '', NaN, 'jjj'];

// console.log(arr.filter(item => item).join());


const arr = [
  { role: 'agent', message: '111' },
  { role: 'user', message: '222' },
]

const lastMessage = arr.findLast(item => item.role === 'agent')

lastMessage = {
  ...lastMessage,
  message: 'hi'
}

console.log(arr)